package com.mypage.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.mypage.bean.EventData;

public class EventExpandableListAdapter extends BaseExpandableListAdapter {
	public EventData eventData;
	public Context mContext;
	private String mEns = RunTimeManager.getInstance().getlanguage();
	public EventExpandableListAdapter(Context con,EventData data ){
		this.eventData = data;
		this.mContext = con;
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return eventData.getData().size();
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return eventData.getData().get(groupPosition).getDatas().size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return eventData.getData().get(groupPosition).getDatas().get(childPosition);
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View mParent = View.inflate(mContext, R.layout.event_fragment_item,null);
		mParent.setPadding(0,0,0,0);
		TextView timeLeft = (TextView) mParent.findViewById(R.id.timeLeft);
		String sss = eventData.getData().get(groupPosition).getDate();
		if (sss.equals("今天")) {
			
			if ("en".equals(mEns)) {
				timeLeft.setText("Today");
			}else{
				timeLeft.setText(eventData.getData().get(groupPosition).getDate());
		}
			
		
//			timeLeft.setTextSize(17);
			timeLeft.setTextColor(mContext.getResources().getColor(R.color.red));
		}else{
			timeLeft.setText(eventData.getData().get(groupPosition).getDate());
			timeLeft.setTextColor(mContext.getResources().getColor(R.color.dark_gray));
		}
	
		
		return mParent;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View mChild = View.inflate(mContext, R.layout.event_fragment_item_,null);
		mChild.setPadding(0,0,0,0);
		TextView timeId = (TextView) mChild.findViewById(R.id.timeId);//当天的时间
		ImageView yesImg = (ImageView) mChild.findViewById(R.id.yesImg_);//任务没完成
		ImageView noImg = (ImageView) mChild.findViewById(R.id.noImg_);//任务没完成
		TextView eatText = (TextView) mChild.findViewById(R.id.eatText);//要显示的文字
		TextView eatTextTwo = (TextView) mChild.findViewById(R.id.eatTextTwo);
		int Pos = childPosition;
		int s = Pos;
		String mRemark = eventData.getData().get(groupPosition).getDatas().get(childPosition).getRemark();
		//这是要显示的文字
		String mSubject = eventData.getData().get(groupPosition).getDatas().get(childPosition).getSubject();
		//判断是否为任务的依据
		String mIs_task = eventData.getData().get(groupPosition).getDatas().get(childPosition).getIs_task();
		//判断任务是否完成
		String mIs_completed = eventData.getData().get(groupPosition).getDatas().get(childPosition).getIs_completed();
		//获取时间
		String mTime = eventData.getData().get(groupPosition).getDatas().get(childPosition).getTime();
		eatTextTwo.setText(mRemark);
		if (mIs_task.equals("0")) {
			timeId.setText(mTime);
			timeId.setVisibility(View.VISIBLE);
			eatText.setText(mSubject);
//			eatTextTwo.setText(mRemark);
			yesImg.setVisibility(View.GONE);
			noImg.setVisibility(View.GONE);
		}else{
			eatText.setText(mSubject);
//			eatTextTwo.setText(mRemark);
			if (mIs_completed.equals("1")) {
				yesImg.setVisibility(View.VISIBLE);
				noImg.setVisibility(View.GONE);
			}else{
				yesImg.setVisibility(View.GONE);
				noImg.setVisibility(View.VISIBLE);
			}
		}
		return mChild;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return false;
	}
}
